package com.encryptdemo.encrypt.config;

import com.encryptdemo.encrypt.aop.EncryptDecryptInterceptor;
import com.encryptdemo.encrypt.filter.RequestWrapperFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private EncryptDecryptInterceptor encryptDecryptInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(encryptDecryptInterceptor).addPathPatterns("/**");
    }
    @Bean
    public FilterRegistrationBean<RequestWrapperFilter> loggingFilter() {
        FilterRegistrationBean<RequestWrapperFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new RequestWrapperFilter());
        registrationBean.addUrlPatterns("/*");
        return registrationBean;
    }
}
